<?php
/**
 *
 * @authors generator
 * @date    2020-10-16 11:29:50
 */

namespace App\Commons\Domain\Module\UserCenter\Model;

use App\Commons\Domain\Casts\CdnUrl;
use App\Commons\Domain\Core\Model;
use App\Commons\Domain\Module\Coin\Model\ExtractAddress;
use App\Commons\Domain\Module\UserCenter\Model\Account;
use App\Commons\Domain\Traits\Common\GenderTextTrait;
use App\Commons\Domain\Traits\MobileMask\MobileMask;
use Illuminate\Auth\Authenticatable;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Tymon\JWTAuth\Contracts\JWTSubject;

/**
 * App\Commons\Domain\Module\UserCenter\Model\Member
 *
 * @property int $id
 * @property \Illuminate\Support\Carbon $created_at
 * @property \Illuminate\Support\Carbon $updated_at
 * @property string $uid 用户uid
 * @property string $username 用户名
 * @property string $mobile 手机号
 * @property string $nickname 昵称
 * @property int $gender 性别，0未知、1男、2女
 * @property mixed $avatar 头像地址
 * @property string $email 邮箱地址
 * @property string|null $disabled_at 是否禁用，有值则禁用
 * @property string $realname 真实名称
 * @property string|null $jy_password 支付密码
 * @property int $email_setting 邮件通知状态：1.在离线都接收、2仅离线接收、3都不接收
 * @property int $sms_setting 短信通知状态：1.在离线都接收、2仅离线接收、3都不接收
 * @property int $country_id 国家id
 * @property int $type 用户类型：1客户，9管理员
 * @property-read \Illuminate\Database\Eloquent\Collection|ExtractAddress[] $ExtractAddress
 * @property-read int|null $extract_address_count
 * @property-read Account|null $account
 * @property-read mixed $gender_text
 * @method static \Illuminate\Database\Eloquent\Builder|Member newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Member newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Member query()
 * @method static \Illuminate\Database\Eloquent\Builder|Member whereAvatar($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Member whereCountryId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Member whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Member whereDisabledAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Member whereEmail($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Member whereEmailSetting($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Member whereGender($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Member whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Member whereJyPassword($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Member whereMobile($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Member whereNickname($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Member whereRealname($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Member whereSmsSetting($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Member whereType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Member whereUid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Member whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Member whereUsername($value)
 * @mixin \Eloquent
 * @property-read \Illuminate\Database\Eloquent\Collection|ExtractAddress[] $extractAddress
 */
class Member extends Model implements
    AuthorizableContract,
    AuthenticatableContract,
    JWTSubject
{
    use Authenticatable;
    use Authorizable;
    use GenderTextTrait;
    use MobileMask;
    use HasFactory;

    protected $casts = [
        'avatar' => CdnUrl::class . ':image'
    ];

    protected $dates = ['disabled_at'];

    /**
     * Get the name of the unique identifier for the user.
     *
     * @return string
     */
    public function getAuthIdentifierName()
    {
        return 'uid';
    }

    /**
     * Get the identifier that will be stored in the subject claim of the JWT.
     *
     * @return mixed
     */
    public function getJWTIdentifier()
    {
        return $this->{$this->getAuthIdentifierName()};
    }

    /**
     * Return a key value array, containing any custom claims to be added to the JWT.
     *
     * @return array
     */
    public function getJWTCustomClaims()
    {
        return [];
    }

    public function account()
    {
        return $this->hasOne(Account::class, 'uid', 'uid');
    }

    public function extractAddress()
    {
        return $this->hasMany(ExtractAddress::class, 'uid', 'uid');
    }
}
